// 语言工具函数
export const STORAGE_LANGUAGE_KEY = 'surf_app_language'

// 获取存储的语言或默认值
export const getStoredLanguage = () => {
  try {
    const storedLang = localStorage.getItem(STORAGE_LANGUAGE_KEY)
    return storedLang && ['zh', 'en'].includes(storedLang) ? storedLang : 'en' // 默认英文
  } catch (e) {
    console.error('无法访问localStorage', e)
    return 'en' // 出错时默认英文
  }
}

// 设置语言并存储
export const setLanguage = (lang) => {
  try {
    if (['zh', 'en'].includes(lang)) {
      localStorage.setItem(STORAGE_LANGUAGE_KEY, lang)
      return true
    }
    return false
  } catch (e) {
    console.error('无法访问localStorage', e)
    return false
  }
} 